const { Client } = require('@stomp/stompjs');

const client = new Client({
    brokerURL: 'ws://localhost:8080/ws',
    debug: function(str) {
        console.log('DEBUG:', str); // 输出所有底层通信
    },
    onConnect: () => {
        console.log("✅ 连接成功");
        
        // 订阅主题
        client.subscribe('/topic/messages', message => {
            console.log('📨 收到消息:', message.body);
        });
        
        // 发送测试消息
        client.publish({
            destination: '/app/chat',
            body: 'Hello from StompJS'
        });
    },
    onStompError: frame => {
        console.error('❌ STOMP协议错误:', frame.headers.message);
    }
});

client.activate();